// 打开的相关动作
var openAction=[
	"打开",
    "查看",
    "查看了解一下",
    "切换为成至",
    "返回到",
    "进入"
 ];
 var openActionStr=openAction.join('');
    
 // 关闭的相关动作
 var closeAction=[
    "关了掉闭",
    "退出",
    "结束"
 ];
 var closeActionStr=closeAction.join('');
 
 // 功能模块
 var moduleNames=[
    "系统",
    "语义识别",
    "平台首页",
    "单位首页",
    "设备一张图",
    "高危信号",
    "重大问题",
    "安全指数",
    "呼叫中心",
    "接处警",
    "日常巡检",
    "隐患整改",
    "消防维保",
    "消防供水",
    "电气火灾",
    "设备详情",
    "工具箱",
    "系统设置"
 ];    
 
 // 标注类型
 var markerNames=[];
 
 // 消防设施类别名称
 var className=[];
 
 // 匹配关键词库
 var matchKeys=[
    {
        ft:100000, //100000 系统
        mt:closeActionStr+"系统平台监控中心大屏客户端"
    },{
        ft:100100, //100100 语义识别
        mt:closeActionStr+"语音意识别助手工具模块",
    },{
        ft:100200, //100200 工具箱
        mt:openActionStr+"工具箱"
    },{
        ft:100201, //100201 工具箱
        mt:closeActionStr+"工具箱"
    },{
        ft:100202, //100202 工具箱
        mt:"开始飞行"
    },{
        ft:100203, //100203 工具箱
        mt:"停止飞行"
    },{
        ft:100204, //100204 工具箱
        mt:"暂停飞行"
    },{
        ft:100205, //100205 工具箱
        mt:"加速飞行"
    },{
        ft:100206, //100206 工具箱
        mt:"减速飞行"
    },{
        ft:100207, //100207 工具箱
        mt:"切换地图主题"
    },{
        ft:100300, //100300 系统设置
        mt:openActionStr+"系统设置"
    },{
        ft:100301, //100301 系统设置
        mt:closeActionStr+"系统设置"
    },{
        ft:100400, //100400 平台首页 
        mt:openActionStr+"平台消防整体实时情况状态状况数据首页详情主页"
    },{
        ft:100500, //100500 单位首页
        mt:openActionStr+"单位消防整体情况状态状况数据首页详情主页"
    },{
        ft:100501 , //100501  单位首页 
        mt:closeActionStr+"单位首页"
    },{
        ft:100600, //100600 设备一张图 
        mt:openActionStr+"消防整体详情实时情况状态状况数据主页设备一张图"
    },{
        ft:100601, //100601 设备一张图 
        mt:closeActionStr+"设备一张图详情"
    },{
        ft:100700, //100700 高危信号 
        mt:openActionStr+"实时历史的高危信号详情情况状态状况据主页"
    },{
        ft:100701, //100701 高危信号 
        mt:closeActionStr+"高危信号详情"
    },{
        ft:100800, //100800 重大问题 
        mt:openActionStr+"实时历史的重大问题详情情况状态状况据主页"
    },{
        ft:100801, //100801 重大问题 
        mt:closeActionStr+"重大问题详情"
    },{
        ft:100900, //100900 安全指数 
        mt:openActionStr+"的单位安全指数基本详情情况数据主页"
    },{
        ft:100901, //100901 安全指数 
        mt:closeActionStr+"安全指数详情"
    },{
        ft:101000, //101000 呼叫中心 
        mt:openActionStr+"呼叫中心数据详情主页"
    },{
        ft:101001, //101001 呼叫中心 
        mt:closeActionStr+"呼叫中心详情"
    },{
        ft:101002, //101002 呼叫中心 
        mt:"呼叫打电话给语音视频通话"
    },{
        ft:101003, //101003 呼叫中心 
        mt:"改切换换成到语音视频通话"
    },{
        ft:101100, //101100 接处警
        mt:openActionStr+"的接处警实时警情数据详情据主页"
    },{
        ft:101101, //101101 接处警
        mt:"搜索的接处警实时警情数据详情主页"
    },{
        ft:101102, //101101 接处警
        mt:closeActionStr+"接处警数据详情"
    },{
        ft:101200, //101200 日常巡检
        mt:openActionStr+"日常巡检的完成情况状况状态详情数据主页"
    },{
        ft:101201, //101201 日常巡检
        mt:closeActionStr+"日常巡检详情"
    },{
        ft:101300, //101300 隐患整改
        mt:openActionStr+"隐患整改的完成情况状况状态详情数据"
    },{
        ft:101301, //101301  隐患整改
        mt:closeActionStr+"隐患整改详情"
    },{
        ft:101302, //101302  隐患整改
        mt:openActionStr+"隐患整改清单视图"
    },{
        ft:101400, //101400  消防维保
        mt:openActionStr+"消防维保监管任务的完成情况状况状态详情数据主页"
    },{
        ft:101401, //101401  消防维保
        mt:closeActionStr+"消防维保详情"
    },{
        ft:101402, //101402  消防维保
        mt:openActionStr+"消防维保时间视图"
    },{
        ft:101403, //101403  消防维保
        mt:closeActionStr+"消防维保时间视图"
    },{
        ft:101500, //101500  设备详情
        mt:openActionStr+"消防供水的传感器设备详情详情情况状态高危信号状况据主页"
    },{
        ft:101501, //101501  设备详情
        mt:closeActionStr+"设备详情"
    },{
        ft:101600, //101600  地图操作
        mt:openActionStr+"楼栋室内三维地图数据"
    },{
        ft:101601, //101601  地图操作
        mt:closeActionStr+"具体的室外楼栋地图场景"
    }];

 // 关键词匹配，获取百分比
function txtMatch(keys,_matchKeys){
    var str = 0;
    for(var i=0;i<_matchKeys.length;i++){
       var tmp = _matchKeys.substr(i,1);
       if ( keys.indexOf(tmp)>-1 )
          str ++;
	}
	let rslt=(str/_matchKeys.length).toFixed(4);
	if(rslt>1){
		rslt=1;
	}
    return rslt;
}

// 数组对象排序
function compare(property){
    return function(a,b){
        var value1 = a[property];
        var value2 = b[property];
        return value2 - value1;
    }
}
 
// 匹配结果 rslt
function resolveResult(rslt){
	// 识别匹配结果
	var cmdRslt;
	switch(rslt.ft){
		case 100000:
			cmdRslt={
				fType:100000,
    			sType:100,
    			desc:"关闭监控中心大屏"
			};
			break;
		case 100100:
			cmdRslt={
				fType:100100,
    			sType:100,
    			desc:"关闭语义识别助手"
			};
			break;
		case 100200:
			cmdRslt={
				fType:100200,
    			sType:100,
    			desc:"打开工具箱"
			};
			break;
		case 100201:
			cmdRslt={
				fType:100201,
    			sType:100,
    			desc:"关闭工具箱"
			};
			break;
		case 100202:
			cmdRslt={
				fType:100202,
    			sType:100,
    			desc:"开始飞行"
			};
			break;
		case 100203:
			cmdRslt={
				fType:100203,
    			sType:100,
    			desc:"停止飞行"
			};
			break;
		case 100204:
			cmdRslt={
				fType:100204,
    			sType:100,
    			desc:"暂停飞行"
			};
			break;
		case 100205:
			cmdRslt={
				fType:100205,
    			sType:100,
    			desc:"加速飞行"
			};
			break;
		case 100206:
			cmdRslt={
				fType:100206,
    			sType:100,
    			desc:"减速飞行"
			};
			break;
		case 100207:
			cmdRslt={
				fType:100207,
    			sType:100,
    			desc:"切换地图主题"
			};
			break;
		case 100300:
			cmdRslt={
				fType:100300,
    			sType:100,
    			desc:"打开系统设置"
			};
			break;
		case 100301:
			cmdRslt={
				fType:100301,
    			sType:100,
    			desc:"关闭系统设置"
			};
			break;
		case 100400:
			cmdRslt={
				fType:100400,
    			sType:100,
    			desc:"返回平台首页"
			};
			break;
		case 100500:
			cmdRslt={
				fType:100500,
    			sType:100,
    			desc:"打开单位首页"
			};
			break;
		case 100501:
			cmdRslt={
				fType:100501,
    			sType:100,
    			desc:"关闭单位首页"
			};
			break;
		case 100600:
			cmdRslt={
				fType:100600,
    			sType:100,
    			desc:"打开设备一张图"
			};
			break;
		case 100601:
			cmdRslt={
				fType:100601,
    			sType:100,
    			desc:"关闭设备一张图"
			};
			break;
		case 100700:
			cmdRslt={
				fType:100700,
    			sType:100,
    			desc:"查看高危信号详情"
			};
			break;
		case 100701:
			cmdRslt={
				fType:100701,
    			sType:100,
    			desc:"关闭高危信号详情"
			};
			break;
		case 100800:
			cmdRslt={
				fType:100800,
    			sType:100,
    			desc:"查看重大问题详情"
			};
			break;
		case 100801:
			cmdRslt={
				fType:100801,
    			sType:100,
    			desc:"关闭重大问题详情"
			};
			break;
		case 100900:
			cmdRslt={
				fType:100900,
    			sType:100,
    			desc:"打开安全指数详情"
			};
			break;
		case 100901:
			cmdRslt={
				fType:100901,
    			sType:100,
    			desc:"关闭安全指数详情"
			};
			break;
		case 101000:
			cmdRslt={
				fType:101000,
    			sType:100,
    			desc:"打开呼叫中心详情"
			};
			break;
		case 101001:
			cmdRslt={
				fType:101001,
    			sType:100,
    			desc:"关闭呼叫中心详情"
			};
			break;
		case 101002:
			cmdRslt={
				fType:101002,
    			sType:100,
    			desc:"切换到视频通话"
			};
			break;
		case 101003:
            cmdRslt={
				fType:101003,
    			sType:100,
    			desc:"切换到语意通话"
			};
			break;
		case 101100:
			cmdRslt={
				fType:101100,
    			sType:100,
    			desc:"打开接处警详情"
			};
			break;
		case 101101:
		case 101102:
			cmdRslt={
				fType:101101,
    			sType:100,
    			desc:"关闭接处警详情"
			};
			break;
		case 101200:
			cmdRslt={
				fType:101200,
    			sType:100,
    			desc:"打开日常巡检详情"
			};
			break;
		case 101201:
			cmdRslt={
				fType:101201,
    			sType:100,
    			desc:"关闭日常巡检详情"
			};
			break;
		case 101300:
			cmdRslt={
				fType:101300,
    			sType:100,
    			desc:"打开隐患整改详情"
			};
			break;
		case 101301:
			cmdRslt={
				fType:101301,
    			sType:100,
    			desc:"关闭隐患整改详情"
			};
			break;
		case 101302:
			cmdRslt={
				fType:101302,
    			sType:100,
    			desc:"打开隐患整改清单视图"
			};
			break;
		case 101400:
			cmdRslt={
				fType:101400,
    			sType:100,
    			desc:"打开消防维保详情"
			};
			break;
		case 101401:
			cmdRslt={
				fType:101401,
    			sType:100,
    			desc:"关闭消防维保详情"
			};
			break;
		case 101402:
			cmdRslt={
				fType:101402,
    			sType:100,
    			desc:"打开消防维保时间视图"
			};
			break;
		case 101403:
			cmdRslt={
				fType:101403,
    			sType:100,
    			desc:"关闭消防维保时间视图"
			};
			break;
		case 101500:
			cmdRslt={
				fType:101500,
    			sType:100,
    			desc:"打开设备详情"
			};
			break;
		case 101501:
			cmdRslt={
				fType:101501,
    			sType:100,
    			desc:"关闭设备详情"
			};
			break;
		case 101600:
			cmdRslt={
				fType:101600,
    			sType:100,
    			desc:"打开到室内场景？"
			};
			break;
		case 101601:
			cmdRslt={
				fType:101601,
    			sType:100,
    			desc:"返回到室外场景"
			};
			break;
		default:
			cmdRslt={
				fType:0,
				sType:0,
				desc:"未识别到结果:"+rslt.ft
			};
			break;
	}
	return cmdRslt;
}

 // 匹配top命令词，topN：top几，discernTxt：识别文本
function matchTopCmd(topN,discernTxt){
	// 匹配结果
	var matchRslts=[];
	for(var i=0;i<matchKeys.length;i++){
		matchRslts.push({
			ft:matchKeys[i].ft,
			dn:matchKeys[i].mt,
			sc:txtMatch(matchKeys[i].mt,discernTxt)
		});
	}

	// 排序，取topN
    matchRslts=matchRslts.sort(compare('sc'));
    if(matchRslts.length>topN){
        matchRslts=matchRslts.slice(0,topN);
    }

    // 再解析，返回结果
    var resolveRslts=[];
    for(var i=0;i<matchRslts.length;i++){
        let matchRslt=matchRslts[i];
        let _rRslt=resolveResult(matchRslt);
		_rRslt.score=matchRslt.sc;
		_rRslt.desc=i+1+"."+_rRslt.desc;
        resolveRslts.push(_rRslt);
    }
    return resolveRslts;
}
export{
    matchTopCmd
}